// https://www.cnblogs.com/fanwenhao/p/10573641.html
import axios from 'axios'

// 开启浏览器端cookie传递
axios.defaults.withCredentials = true

const EDU_SERVER_API = 'http://127.0.0.1/api/v2'

const options = {}
options.baseURL = EDU_SERVER_API

const ax = {
  options: options,
  get: (req, url) => {
    options.headers = {
      Cookie: req.headers.cookie + ';'
    }
    url = options.baseURL + url
    return axios.get(url, options)
  }
}

// 为了在 asyncData 方法中使用
export default ({ app }, inject) => {
  // Set the function directly on the context.app object
  app.$global = {
    ax: ax
  }
}
